package wnhz.com.business.freeshop.fragment;

import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseRVAdapter;
import wnhz.com.business.base.BaseViewHolder;
import wnhz.com.business.base.MyBaseActivity;
import wnhz.com.business.base.MyBaseFragment;
import wnhz.com.business.impl.ActionBarClickListener;
import wnhz.com.business.view.TranslucentActionBarW;

/**
 * Created by Administrator on 2017/9/21 0021.
 */

public class ThridFragment extends MyBaseFragment implements ActionBarClickListener, View.OnClickListener {
    @BindView(R.id.action_bar)
    TranslucentActionBarW actionBar;
    @BindView(R.id.recycler_car)
    RecyclerView recyclerCar;
    @BindView(R.id.tv_txt)
    TextView tvTxt;
    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_makepay)
    TextView tvMakepay;
    Unbinder unbinder;
    private MyBaseActivity activity;

    private Boolean makesure = true;
    private List<String> itemdata = new ArrayList<>();

    @Override
    protected void handleMsg(Message msg) {

    }

    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_free_thrid, container, false);
        return view;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        activity = (MyBaseActivity) getActivity();
        actionBar.setData("购物车", 0, null, 0, "编辑", 0, this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //沉浸
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //改变状态栏颜色
            activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            actionBar.setStatusBarHeight(getStatusBarHeight());
        }

        initview();
        initdatabuy();
        return rootView;
    }

    private void initview() {

        recyclerCar.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        itemdata.clear();
        for (int i = 0; i < 2; i++) {
            itemdata.add("h" + i);
        }
    }


    private void initdatabuy() {
        recyclerCar.setAdapter(new BaseRVAdapter(getContext(), itemdata) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_car_f;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {

            }

            @Override
            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

            }
        });
    }

    private void initdatadelete() {
        recyclerCar.setAdapter(new BaseRVAdapter(getContext(), itemdata) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_cardelete_f;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {

            }

            @Override
            public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onLeftClick() {

    }

    @Override
    public void onRightClick() {
        if (makesure) {
            initdatadelete();
            tvTxt.setText("已选");
            tvNumber.setText("2个");
            tvMakepay.setText("删除");
            tvMakepay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                }
            });
            makesure = false;
        } else {
            initdatabuy();
            tvTxt.setText("合计");
            tvNumber.setText("¥160");
            tvMakepay.setText("确认支付");
            makesure = true;
            tvMakepay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                }
            });
        }
    }

    @Override
    public void onEditTextClick() {

    }

    @Override
    public void onClick(View view) {

    }
}
